from soaplib.serializers.clazz import ClassSerializer
from soaplib.serializers.primitive import Integer, String, Array, Boolean, Float, \
                                          DateTime

class EditionSoap(ClassSerializer):
    class types:
        id = Integer
        name = String
        description = String

class AddressSoap(ClassSerializer):
    class types:
        id = Integer
        address = String
        postalcode = String
        city = String
        province = String
        country = String
        type = String
        subject = Integer

class SubjectSoap(ClassSerializer):
    class types:
        id = Integer
        #users = OneToMany('User', cascade='all')

class BookshopSoap(ClassSerializer):
    class types:
        id = Integer
        company_name = String
        vat = String
        iban = String
        orders = Array(Integer)
        addresses = Array(AddressSoap)
        
class UserSoap(ClassSerializer):
    class types:
        id = Integer
        username = String
        password = String
        email = String
        registration_date = String
        last_modify_date = String
        active = Boolean
        subject = Integer
        type = String
        tmstp = String
        
class BookSoap(ClassSerializer):
    class types:
        id = Integer
        title = String
        description = String
        authors = Array(Integer)
        genres = Array(Integer)
        products = Array(Integer)
        
class AuthorSoap(ClassSerializer):
    class types:
        id = Integer
        name = String
        surname = String
        books = Array(Integer)
        addresses = Array(AddressSoap)
    
class AdminSoap(ClassSerializer):
    class types:
        name = String
        surname = String
        
class GenreSoap(ClassSerializer):
    class types:
        id = Integer
        name = String
        description = String
        #books = ManyToMany('Book', tablename='book_has_genres')

class ProductBookSoap(ClassSerializer):
    class types:
        product = Integer
        book = Integer
        title = String
        sequence_num = Integer

class ProductSoap(ClassSerializer):
    class types:
        id = Integer
        name = String
        description = String
        edition = Integer
        price = Float
        quantity = Integer
        discount = Float
        orders = Array(Integer)
        books = Array(ProductBookSoap)

class EditionSoap(ClassSerializer):
    class types:
        id = Integer
        name = String
        description = String
        #products = OneToMany('Product')
    
class OrderDetailSoap(ClassSerializer):
    class types:
        order = Integer
        product = Integer
        quantity = Integer
        pamount = Integer

class OrderSoap(ClassSerializer):
    class types:
        id = Integer
        bookshop = BookshopSoap
        date = DateTime
        status = String
        total_amount = Float
        detail = Array(OrderDetailSoap)

class PrintSoap(ClassSerializer):
    class types:
        id = Integer
        product = Integer
        name = String
        date = DateTime
        quantity = Integer
        number = Integer # A trigger in the database calculate this field

class Stats(ClassSerializer):
    class types:
        id = Integer
        name = String
        edition = String
        prints = Integer
        price = Float
        sold = Integer
        quantity = Integer